<?php

namespace maoxuner\LaravelJsonRpc\Exceptions;

use Throwable;

/**
 * The error codes from and including -32768 to -32000 are reserved for pre-defined errors.
 */
class RpcException extends BaseException
{
    public function __construct(string $message = '', int $code = 0, ?Throwable $previous = null)
    {
        if ($code < -32768 || $code > -32000) {
            $code = -32000;
        }

        parent::__construct(
            $this->message ?? $message,
            $this->code ?? $code,
            $previous
        );
    }
}
